<template>
  <div class="technicianManagementList">
    <!-- 中部查询条件 -->
    <UserSearch @search="reload"></UserSearch>
    <el-card class="box-card"
             shadow="never">
      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     cache-key="systemUserTable">
        <!-- 名字 -->
        <template v-slot:realName="{ row }">
          <div class="realNameStyle">
            <img class="avaterName"
                 :src="row.head"
                 alt="" />
            <span>{{ row.technicianName }}</span>
          </div>
        </template>
        <!-- 实名认证 -->
        <template v-slot:authenticationNot="{ row }">
          <el-link :underline="false"
                   :type="authenticationNotType(row.authenticationNot).type">
            {{ authenticationNotType(row.authenticationNot).status }}
          </el-link>
        </template>
        <!-- 服务状态 -->
        <template v-slot:status="{ row }">
          <el-tag :underline="false"
                  :type="serviceType(row.status).type">
            {{ serviceType(row.status).status }}
          </el-tag>
        </template>
        <!-- 技能评分 -->
        <template v-slot:scoreTotal="{ row }">
          <el-rate v-if="row?.authenticationNot == '3'"
                   v-model="row.scoreTotal"
                   disabled
                   text-color="#ff9900">
          </el-rate>
          <div v-else> - - - - - - </div>
        </template>
        <template v-slot:serviceOrder="{ row }">
          <div v-if="row?.authenticationNot == '3'">{{ row.serviceOrder }}</div>
          <div v-else> - - - - - - </div>
        </template>

        <!-- 性别 -->
        <template v-slot:sex="{ row }">
          <div style="color: #1890ff"
               v-if="row.gender == 1">男</div>
          <div style="color: #f09"
               v-if="row.gender == 2">女</div>
        </template>
        <!-- 操作 -->
        <template v-slot:action="{ row }">
          <el-link v-if="row?.authenticationNot !== 4"
                   icon="el-icon-tickets"
                   type="primary"
                   :underline="false"
                   @click="viewDetail(row)">
            查看详情
          </el-link>
          <el-link icon="el-icon-document-delete"
                   v-if="row?.authenticationNot == 4"
                   type="danger"
                   :underline="false"
                   @click="viewDetail(row)">
            驳回原因
          </el-link>
          <el-link v-if="row?.authenticationNot == 3"
                   type="info"
                   icon="el-icon-edit-outline"
                   :underline="false"
                   @click="viewStatus(row)">
            状态
          </el-link>
          <!-- <el-link v-if="row.auditStatus==2" type="info"
                   :underline="false"
                   @click="modifyRate()">
            状态
          </el-link> -->

          <el-link v-if="row?.authenticationNot == 3"
                   type="info"
                   :underline="false"
                   icon="el-icon-chat-dot-square"
                   @click="viewComment(row)">
            评论
          </el-link>

          <el-popconfirm class="ele-action"
                         title="是否确定要删除该条信息"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link icon="el-icon-delete"
                       type="danger"
                       :underline="false">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 详情页面 -->
    <drawerDetail :detailData="technicianDetail"
                  :drawer.sync="drawer"></drawerDetail>
    <!-- 评论页面 -->
    <drawerComment :drawComment.sync="drawComment"
                   :data="current"></drawerComment>
    <!-- 技师状态 -->
    <technicianStatusEdit :id="id"
                          :status="status"
                          :visible.sync="visible"
                          @done="reload">
    </technicianStatusEdit>
  </div>
</template>
<script>
import UserSearch from './user-search.vue';
import technicianStatusEdit from './technicianStatusEdit.vue';
import drawerComment from './drawerComment.vue';
import drawerDetail from './drawerDetail.vue';
import {
  serviceStatusList,
  realNameAuthenticationList,
  technicianManagementList
} from '../constant/constant';
import {
  technicianList,
  getByTechnicianComments,
  technicianDetail,
  technicianDelete,
  technicianUpdate
} from '@/api/technicianManagement/technicianList';
export default {
  name: 'TechnicianManagementList',

  components: {
    // 查看详情
    drawerDetail,
    // 评论
    drawerComment,
    UserSearch,
    technicianStatusEdit
  },

  data () {
    return {
      technicianManagementList,
      //  技能评分
      colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
      value: 4,
      id: '',
      status: '',
      // 表格列配置
      columns: [
        // {
        //   columnKey: 'selection',
        //   type: 'selection',
        //   width: 45,
        //   align: 'center',
        //   fixed: 'left'
        // },
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'realName',
          label: '名称',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'realName'
        },
        {
          prop: 'sex',
          label: '性别',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'sex'
        },
        {
          prop: 'authenticationNot',
          label: '实名认证',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'authenticationNot'
        },
        {
          prop: 'status',
          label: '服务状态',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'status'
        },
        {
          prop: 'mobile',
          label: '电话',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },

        {
          prop: 'scoreTotal',
          label: '技能评分',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 150,

          slot: 'scoreTotal'
        },
        {
          prop: 'serviceOrder',
          label: '服务订单',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'serviceOrder'
        },
        {
          prop: 'city',
          label: '省市区',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },
        {
          prop: 'address',
          label: '详细地址',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },
        {
          prop: 'createdAt',
          label: '创建时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          prop: 'updatedAt',
          label: '更新时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 320,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true,

          fixed: 'right'
        }
      ],
      // 表格选中数据
      selection: [],
      // 抽屉是否显示
      drawer: false,
      // 评论是否显示
      drawComment: false,
      //   状态是否谈出
      visible: false,
      //  技师详情
      technicianDetail: null,
      current: null
    };
  },
  activated () {
    this.reload()
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    },

    // 服务状态
    serviceType () {
      return function (serviceType) {
        // console.log(applyType)
        if (serviceType == '1') {
          return {
            status: '离线中',
            type: 'info'
          };
        } else if (serviceType == '2') {
          return {
            status: '在线',
            type: 'success'
          };
        } else if (serviceType == '3') {
          return {
            status: '已冻结',
            type: 'danger'
          };
        } else {
          return {
            status: '服务中',
            type: 'primary'
          };
        }
      };
    },
    // 实名认证
    authenticationNotType () {
      return function (authenticationNotType) {
        console.log(authenticationNotType);
        if (authenticationNotType == 1) {
          return {
            status: '未认证',
            type: 'info'
          };
        } else if (authenticationNotType == 2) {
          return {
            status: '认证中',
            type: 'warning'
          };
        } else if (authenticationNotType == 3) {
          return {
            status: '已认证',
            type: 'success'
          };
        } else {
          return {
            status: '认证失败',
            type: 'danger'
          };
        }
      };
    }
  },
  methods: {
    // 点击查看详情弹出详情抽屉
    async viewDetail (row) {
      const res = await technicianDetail(row.id);
      console.log(res);
      this.technicianDetail = res;

      // 用户余额管理
      this.drawer = !this.drawer;
    },

    // 查看评论
    async viewComment (row) {
      const res = await getByTechnicianComments({
        technicianId: row.id,
        siteId: this.$store.state.site.info.id,
        page: 1,
        limit: 10
      });
      this.current = res;
      console.log(res);
      // 评论
      this.drawComment = !this.drawComment;
    },

    // 查看状态
    viewStatus (row) {
      this.id = row.id;
      this.status = row.status;
      this.visible = !this.visible;
    },


    /* 刷新表格 */
    reload (where) {
      this.$refs.table.reload({ page: 1, where: where, types: 1 });
      drawerComment,
        // 技师状态
        technicianStatusEdit,
        UserSearch
    },
    /* 表格数据源 */
    async datasource ({ page, limit, where, order }) {
      const res = await technicianList({
        page,
        limit,
        ...where,
        siteId: this.$store.state.site.info.id
      });
      res.list.forEach((item) => {
        if (item.scoreTotal == 5.0) {
          item.scoreTotal = 5;
        }
        item.scoreTotal = item.scoreTotal ? item.scoreTotal : 5;
      });
      return res;
      //   return Promise.resolve({ count: 2, list: technicianManagementList });
    },


    /* 删除 */
    remove (row) {
      const loading = this.$loading({ lock: true });
      technicianDelete(row.id)
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    },
    /* 批量删除 */
    removeBatch () {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的套餐吗?', '提示', {
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({ lock: true });
          removeMeal({ ids: this.selection.map((d) => d.id) })
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        })
        .catch(() => { });
    }
  }
};
</script>
<style lang="less" scoped>
.technicianManagementList {
  .realNameStyle {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .avaterName {
      width: 32px;
      height: 32px;
      border-radius: 32px;
      vertical-align: middle;
      margin-right: 5px;
    }
  }
}
</style>
